//自定义按钮级别权限指令

import store from '~/store'

function hasPermission(value,el=false){
    if(!Array.isArray(value)){
        throw new Error('需要配置该接口权限')
    }
    const hasAuth =value.findIndex(v=>store.state.ruleNames.includes(v)) !=-1

    //节点是否存在 并且没有这个权限
    if(el&&!hasAuth){
        el.parentNode &&el.parentNode.removeChild(el)
    }

    return hasAuth
}

export default {
    install(app){
        app.directive('permission',{
            mounted(el,binding) {
                hasPermission(binding.value,el)
            },
        })
    }
}